<?php
/**
 * qLogger is class made to log things to log files. 
 * 
 * qLogger uses following scheme of logging:
 * - saves logs in log_path (must be defined by user)
 * - normal logs (qLogger::Log()) are saved to: log_path/log-date.log
 * - error logs (qLogger::LogError()) are saved to: log_path/errorlog-date.log
 * - date's format is: 4-digits year, two digits month, two digits day
 * - timestamp's format, used in files: 2-digits hour (24-hour format), 2-digits minutes, 2-digits seconds.
 */
class qLogger
{
    /**
     * Writes log message, but only when "debug" is defined.
     * @param string $message message to be logged.
     * @return true
     */
    public static function Log($message)
    {
        if (defined("debug"))
            self::_write(1, $message);
        
        return true;
    }
    
    /**
     * Writes error log message.
     * @param type $message error to be logged.
     * @return true
     */
    public static function LogError($message)
    {
        self::_write(2, $message);
        
        return true;
    }
    
    /** 
     * Writes message.
     * @param int $type 1 - log message, 2 - error message
     * @param type $message message to be written
     * @return boolean
     */
    private static function _write($type, $message)
    {
        switch ($type)
        {
            case 1:
                $type = "log-";
                break;
            case 2:
                $type = "errorlog-";
                break;
            default:
                return false;
        }
        
        file_put_contents($type . date("Y-m-d").'.log', date("H:i:s").': '.$message, FILE_APPEND);
        return true;
    }
}